<template>
  <div class="item">
    <div class="icon" @click="onRouteTo(field)" :style="{ backgroundColor: bgColor }">
      <span class="iconfont" :class="icon"></span>
    </div>
    <p class="icon-text">{{ iconText }}</p>
  </div>
</template>

<script>
import {mapMutations} from 'vuex'
export default {
  name: 'CategoryIconsSub',
  props: {
    bgColor: String,
    icon: String,
    iconText: String,
    field: String
  },
  methods: {
    ...mapMutations(['setField']),
    /**
     * 页面跳转
     */
    onRouteTo(field) {
      // 缓存选择的分类
      this.setField(field);
      // 跳转商品分类列表页
      this.$router.push('/list');
    }
  }
};
</script>

<style lang="scss" scoped>
@import '~styles/mixins.scss';
@import '~styles/variables.scss';

.icon-item {
	@include flex-column;
	@include vh-center;
	width: 20%;
	padding: .2rem 0;

	.icon {
		@include vh-center;
		width: .4rem;
		height: .4rem;
		border-radius: 50%;

		.iconfont {
			color: #fff;
			font-size: .26rem;
		}
	}

	.icon-text {
		font-size: .14rem;
		text-align: center;
		margin-top: .1rem;
	}
}
</style>






